﻿
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace AppPressFramework {



                internal class FileTexts
                    {
                    internal static string AppPressJS = "\nvar __IsPageDirty = null;\nvar deletedFormDatas = new Array();\nvar popupDialogs = new Array(),\n    $alertDialog = null,\n    $promptDialog = null;\nvar WarnOnDirtyClose = false;\n\nvar sModalWindowFeatures = {\n    dialogHeight: 450,\n    dialogWidth: 650,\n    status: 'no',\n    resizable: 1\n};\n\nfunction Evaluate(obj) {\n    return eval(\"(\" + obj + \")\")\n}\n\nfunction getKeycode(event) {\n    keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));\n    //if (keycode == 27)\n    //    return true;\n    return false;\n}\n\nfunction RegexValidate(obj, regex, errorObj, errorMessage) {\n    if (obj.val() != '' && !regex.test(obj.val())) {\n        errorObj.html(errorMessage);\n        obj.focus();\n    } else\n        errorObj.html('');\n}\n\nfunction dateValidate(obj, dateFormat, errorObj, errorMessage) {\n    errorObj.html('');\n    if (obj.val() != '') {\n        try {\n            $.datepicker.parseDate(dateFormat, obj.val());\n        } catch (e) {\n            errorObj.html(errorMessage);\n        }\n    }\n}\n\nfunction ResetTableScrollHeaders() {\n    // Change the selector if needed\n	var tablesFound = false;\n    var $table = $('table.TableScroll');\n	$table.each(function(ii,tbl) {\n		tablesFound = true;\n		var $bodyCells = $(tbl).find('tbody tr:first').children(),\n		$headerCells = $(tbl).find('thead tr').children(),\n		colWidth,headerWidth;\n		\n		// Get the tbody columns width array\n		colWidth = $bodyCells.map(function() {\n			return $(this).outerWidth();\n		}).get();\n		// Get the thad columns width array\n		headerWidth = $headerCells.map(function() {\n			return $(this).outerWidth();\n		}).get();\n		// Set the width of thead columns\n		$(tbl).find('thead tr').children().each(function(i, v) {\n			var width = Math.max(colWidth[i],headerWidth[i])+\"px\";\n			\n			$($bodyCells[i]).css({\n                \"min-width\": width,\n                \"max-width\": width,\n                \"width\": width\n            });\n			$(v).css({\n                \"min-width\": width,\n                \"max-width\": width,\n                \"width\": width\n            });\n			});\n		});\n		return tablesFound;\n}\n\nfunction AppPressReady() {\n    // Adjust the width of thead cells when window resizes\n    $(window).resize(ResetTableScrollHeaders).resize(); // Trigger resize handler\n\n\n    $(window).scrollTop();\n    $(document).bind(\"keydown\", function(event) {\n        keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));\n        if (keycode == 27) {\n            event.preventDefault();\n        }\n    });\n\n    SetDirty(false);\n    $(window).bind(\"beforeunload\", function() {\n        try {\n            if (GetDirty() && GetWarnOnDirtyClose()) {\n                return 'You have some un-saved data in this page, do you want to continue with out saving those data?';\n            }\n\n        } catch (e) {\n\n        }\n    });\n\n}\n\nfunction Status() {\n    var statusObj = new Object();\n    statusObj.continueExecution = true;\n    return statusObj;\n}\n\nfunction GetFieldValue(formData, fieldDefId) {\n    for (var j = 0; j < formData.fieldValues.length; ++j) {\n        if (formData.fieldValues[j].fieldDefId == fieldDefId)\n            return formData.fieldValues[j];\n    }\n    alert(\"Internal Error: Could not Find Field with FieldDefId:\" + fieldDefId + \" in FormDefId:\" + formData.formDefId);\n    return null;\n}\n\nfunction SetFieldValue(formDefId, id, fieldDefId, value) {\n		var formData = FindFormData(formDefId, id);\n		for (var j = 0; j < formData.fieldValues.length; ++j) {\n			if (formData.fieldValues[j].fieldDefId == fieldDefId)\n				{\n				formData.fieldValues[j].Value=value;\n				return;\n				}\n		}\n    alert(\"Internal Error: Could not Find Field with FieldDefId:\" + fieldDefId + \" in FormDefId:\" + formData.formDefId);\n}\n\nfunction FindFormData(formDefId, id) {\n\n    for (var j = 0; j < a.formDatas.length; ++j)\n        if (a.formDatas[j] != null && a.formDatas[j].formDefId == formDefId && a.formDatas[j].id == id) {\n            return a.formDatas[j];\n        }\n    alert(\"Internal Error: Could not find FormData with FomDefId:\" + formDefId + \" Id:\" + id);\n    return null;\n}\n\nfunction FindFormField(fieldValue) {\n    for (var j = 0; j < a.formFields.length; ++j)\n        if (a.formFields[j].id == fieldValue.fieldDefId)\n            return a.formFields[j];\n    return null;\n}\n\nfunction stringifyP(a) {\n    return escape(JSON.stringify(a));\n}\n\nfunction JQueryEscape(s) {\n    return s.replace(/:/g, \"\\\\:\");\n}\n\nfunction _AppPress_UpdatePickMultipleOptions(id) {\n    var checkedItems = $('input[name=\"' + JQueryEscape(id) + '\"]:checked');\n    var s = \"\";\n    $.each(checkedItems, function(index, checkedItem) {\n        if (s.length > 0)\n            s += \" | \";\n        s += $(\"label[for='\" + JQueryEscape(id + ':' + checkedItem.value) + \"']\").text();\n    });\n    $(JQueryEscape('#PickMultipleSelection_' + id)).html(s);\n\n}\n\nfunction AppPress_UpdatePickMultipleOptions(id) {\n    _AppPress_UpdatePickMultipleOptions(id)\n    $(JQueryEscape('#PickMultiplePoupup_' + id)).dialog(\"close\");\n}\n\nfunction AppPress_AddPickMultipleToPopupDialogs(id) {\n    if (popupDialogs.length > 0) {\n        var popupDialog = popupDialogs[popupDialogs.length - 1];\n        popupDialog.PopupDivs[popupDialog.PopupDivs.length] = id;\n    }\n}\n\nfunction DialogButtonOnClickFieldName(fieldName) {\n    if (popupDialogs.length == 0)\n        return false;\n    var popupDialog = popupDialogs[popupDialogs.length - 1].popupDialog;\n    for (var i = 0; i < popupDialog.dialogButtons.length; ++i)\n        if (popupDialog.dialogButtons[i].fieldName == fieldName) {\n            eval(popupDialog.dialogButtons[i].onClick);\n            return true;\n        }\n    return false;\n}\n\nfunction AlertMessage(message, width) {\n    if (!width)\n        width = 450;\n    $alertDialog = $('<div></div>')\n        .html(message)\n        .dialog({\n            autoOpen: false,\n            modal: true,\n            closeText: false,\n            width: width,\n            title: \"Alert\",\n            close: function(event, ui) {\n                if ($alertDialog != null) {\n                    $alertDialog.dialog('destroy').remove();\n                    $alertDialog = null;\n                }\n            }\n        });\n\n    $alertDialog.dialog('open');\n}\n\nfunction DialogButtonOnClick(ev) {\n    if (!ev) ev = window.ev;\n    DialogButtonOnClickFieldName($(ev.target).text());\n}\n\nfunction _ExecuteAppPressResponse(pageData,instanceId, clientActions, startIndex) {\n    for (var cai = startIndex; cai < clientActions.length; ++cai) {\n        var ca = clientActions[cai];\n        switch (parseInt(ca.appPressResponseType)) {\n\n            case 10 : //ExecuteJSScript\n                if (ca.JsStr)\n                    try {\n                        eval(ca.JsStr);\n                    } catch (e) {} // ignore errors\n                break;\n            case 20 : // PromptClient\n                $promptDialog = $('<div></div>')\n                    .html(ca.message)\n                    .dialog({\n                        autoOpen: false,\n                        modal: true,\n                        closeText: false,\n                        width: ca.popupWidth == 0 ? 450 : ca.popupWidth,\n                        title: ca.popupTitle == null ? \"Confirm\" : ca.popupTitle,\n                        close: function(event, ui) {\n                            $(this).dialog('destroy').remove();\n                            $promptDialog = null;\n                        },\n                        buttons: {\n                            \"Ok\": function() {\n                                result = true;\n                                $(this).dialog(\"close\");\n                                AjaxFunctionCall(pageData.functionCall, instanceId, ca.id, ca.fieldDefId, false, this, result)\n                            },\n                            \"Cancel\": function() {\n                                $(this).dialog(\"close\");\n                            }\n                        }\n                    });\n\n                $promptDialog.dialog('open');\n                break;\n            case 17 : //FormError\n                var message = ca.message;\n                var obj = $(JQueryEscape(\"#_FormError:\" + ca.formDefId + ':' + ca.id));\n                if (obj.length == 0) {\n                    message = \" Error in Form:\" + ca.formDefId + \" with Id: \" + ca.id + \"\\n\" + $('<div/>').html(message).text();\n                    AlertMessage(message);\n                    break;\n                } else {\n                    var containerObj = $(JQueryEscape(\"#_FormErrorContainer:\" + ca.formDefId + ':' + ca.id));\n                    if (containerObj.length > 0) {\n                        containerObj.toggle(true);\n                    }\n                }\n                obj.html(message);\n                break;\n            case 19 : //SetPageNonDirty\n                SetDirty(false);\n                break;\n            case 1 : //AlertMessage\n                $alertDialog = $('<div></div>')\n                    .html(ca.message)\n                    .dialog({\n                        autoOpen: false,\n                        modal: true,\n                        closeText: false,\n                        width: ca.popupWidth == 0 ? 450 : ca.popupWidth,\n                        title: ca.popupTitle == null ? \"Alert\" : ca.popupTitle,\n                        close: function(event, ui) {\n                            if ($alertDialog != null) {\n                                $alertDialog.dialog('destroy').remove();\n                                $alertDialog = null;\n                            }\n                            _ExecuteAppPressResponse(pageData,instanceId, clientActions, cai + 1);\n                        }\n                    });\n\n                $alertDialog.dialog('open');\n                return;\n            case 9 : //PageRefresh\n                __IsPageDirty = false;\n                DisablePage();\n                location.href = location.href;\n                break;\n            case 3 : //ClearErrors\n                if (ca.fieldDefId) {\n                    var id = 'error:' + ca.formDefId + ':' + ca.fieldDefId + ':' + ca.id;\n                    var obj = $('#' + JQueryEscape(id));\n                    if (obj.length == 1)\n                        obj.html('');\n                } else {\n                    $(\"[id^='\" + JQueryEscape(\"error:\") + \"']\").html('');\n                    try {\n                        $(\"#_FormErrorContainer\").toggle(false);\n                    } catch (e) {}\n                    $(\"#_FormError\").html('');\n                }\n                break;\n            case 4 : // Popup\n                var $popupDialog = $('<div></div>');\n                var popupDialog = new Object();\n                popupDialog.popupDialog = $popupDialog;\n                popupDialog.rootFormName = ca.formDefId;\n                popupDialog.IsPageDirty = false;\n                popupDialog.WarnOnDirtyClose = false;\n                popupDialog.pageTimeStamp = ca.pageTimeStamp;\n                popupDialog.PopupDivs = new Array();\n                popupDialogs.push(popupDialog);\n                $popupDialog.html(ca.fieldHtml);\n\n                $popupDialog.dialog({\n                    autoOpen: false,\n                    modal: true,\n                    closeText: false,\n                    width: ca.popupWidth,\n                    height: ca.popupHeight,\n                    //maxHeight: 600, //Ram: Do not se max height because it becume cause of scroll and also not allow resize height. Height can be passed manually if it is fixed.\n                    title: ca.popupTitle,\n                    open: function(evt, ui) {\n                        if (ca.NoFocus)\n                            $(this).parent().focus();; // set focus to dialog so Escape works\n                        // ??? check if focus on Date then Blur\n						$('textarea').autosize();\n                    },\n                    close: function(event, ui) {\n                        var popupDialog = popupDialogs[popupDialogs.length - 1];\n                        popupDialog.popupDialog.dialog('destroy').remove();\n                        for (var i = 0; i < popupDialog.PopupDivs.length; ++i)\n                            $(JQueryEscape('#PickMultiplePoupup_' + popupDialog.PopupDivs[i])).dialog('destroy').remove();\n                        popupDialogs.pop();\n                        a.pageStackCount--;\n                        // remove FormDatas of popup\n                        for (var i = 0; i < a.formDatas.length; ++i)\n                            if (a.formDatas[i].pageStackIndex > a.pageStackCount)\n                                a.formDatas[i] = null;\n                    },\n                    beforeClose: function(event, ui) {\n                        var popupDialog = popupDialogs[popupDialogs.length - 1];\n                        if (popupDialog.IsPageDirty) {\n                            if (popupDialog.WarnOnDirtyClose)\n                                if (!confirm(\"This dialog is unsaved. Do you really want to close it?\"))\n                                    return false;\n                        }\n                    }\n                });\n                if (ca.popupParams != null && ca.popupParams.dialogButtons != null) {\n                    var dialogButtons = {};\n                    for (var i = 0; i < ca.popupParams.dialogButtons.length; ++i) {\n                        dialogButtons[ca.popupParams.dialogButtons[i].fieldName] = DialogButtonOnClick;\n                    }\n                    $popupDialog.dialogButtons = ca.popupParams.dialogButtons;\n                    $popupDialog.dialog('option', 'buttons', dialogButtons);\n                }\n                $popupDialog.dialog('open');\n                if (ca.JsStr)\n                    eval(ca.JsStr);\n\n                SetFieldReadonly(pageData);\n                popupDialog.p = pageData;\n\n                //return; need to show fieldError from Init\n                break;\n            case 13 : // ClosePopupWindow\n                if (popupDialogs.length > 0) {\n                    var popupDialog = popupDialogs[popupDialogs.length - 1];\n                    popupDialog.popupDialog.dialog('destroy').remove();\n                    for (var i = 0; i < popupDialog.PopupDivs.length; ++i)\n                        $(JQueryEscape('#PickMultiplePoupup_' + popupDialog.PopupDivs[i])).dialog('destroy').remove();\n                    popupDialogs.pop();\n                }\n                break;\n            case 7 : // Redirect\n                if (GetDirty() && GetWarnOnDirtyClose()) {\n                    if (!confirm('You have some un-saved data in this page, do you want to continue with out saving those data?'))\n                        continue;\n                    __IsPageDirty = false; // do not repeat the warning in page unload\n                }\n                DisablePage();\n\n                if (ca.url.indexOf(\"GetPDF=\") > 0) {\n                    window.setTimeout(function() {\n                        RemoveDisablePage();\n                    }, 8000);\n                }\n\n                if (ca.redirectParams == null)\n                    try {\n                        RemoveDisablePage(); // does not finish AjaxFunctionCall. So DiablePageCount remains 1\n                        location.href = ca.url;\n                    } catch (e) {\n                    // jQuery has bug in this case for window closing event\n                } else {\n\n                    var formPost = '';\n                    var formStr = '<form action=\"' + ca.url + '\" method=\"post\"';\n                    $.each(ca.redirectParams.postParams, function(key, value) {\n                        formPost += '<input type=\"hidden\" name=\"' + key + '\" value=\"' + value + '\">';\n                    });\n                    if (ca.redirectParams.target != null) {\n                        if (ca.redirectParams.target != \"_self\")\n                            RemoveDisablePage();\n                        formStr += ' target=\"+ca.redirectParams.target+\"';\n                    }\n                    formStr += '>' + formPost + '</form>';\n                    $(formStr).appendTo('body').submit();\n                }\n\n                break;\n            case 11 : //SetFieldValue\n                var formData = FindFormData(ca.formDefId, ca.id);\n                var fieldValue = GetFieldValue(formData, ca.fieldDefId);\n                var fieldType = FindFormField(fieldValue).Type;\n                switch (fieldType) {\n                    case 2 :\n                    case 1 :\n                    case 3 :\n                    case 4 :\n                    case 11 :\n                        var id = \"AppPress:\" + fieldType + ':' + ca.formDefId + ':' + ca.fieldDefId + ':' + ca.id;\n                        var obj = $(\"#\" + JQueryEscape(id));\n                        obj.val(ca.Value);\n                        break;\n                    case 6 :\n                        var style = FindFormField(fieldValue).Style;\n                        if (style == 5 )\n                            $(\"[Name='\" + JQueryEscape(objId) + \"']:checked\").val(ca.Value);\n                        else if (style == 9 ) {\n                            var obj = $(JQueryEscape(\"#AppPress:\" + fieldType + \":\" + ca.formDefId + ':' + ca.fieldDefId + ':' + ca.id));\n                            obj.val(ca.fieldHtml);\n                            fieldValue.Value = ca.Value;\n                        } else { // FormDefFieldStyle.Dropdown\n                            var obj = $(JQueryEscape(\"#AppPress:\" + fieldType + \":\" + ca.formDefId + ':' + ca.fieldDefId + ':' + ca.id));\n                            obj.val(ca.Value);\n                        }\n                        SetDirty();\n                        break;\n                    case 14 :\n                        var obj = $(JQueryEscape(\"#fieldContainer:\" + formData.formDefId + ':' + ca.fieldDefId + ':' + ca.id));\n                        obj.html(ca.fieldHtml);\n                        break;\n                    case 5 :\n                        if (ca.id == null)\n                            $('input|checkbox[id*=\"' + JQueryEscape(ca.formDefId + ':' + ca.fieldDefId + ':\"]')).attr('checked', ca.Value == '1');\n                        else {\n                            var obj = $(JQueryEscape(\"#AppPress:\" + fieldType + \":\" + formData.formDefId + ':' + ca.fieldDefId + ':' + ca.id));\n                            if (ca.Value == \"1\")\n                                obj.attr(\"checked\", \"checked\");\n                            else\n                                obj.removeAttr(\"checked\");\n                        }\n                        break;\n                }\n                break;\n            case 14 : //SetFocus\n                var formData = FindFormData(ca.formDefId, ca.id);\n                var fieldValue = GetFieldValue(formData, ca.fieldDefId);\n                var objSetFocus = \"#AppPress:\" + FindFormField(fieldValue).Type.toString() + \":\" + ca.formDefId + ':' + ca.fieldDefId + ':' + ca.id;\n                setTimeout(\n                    function() {\n                        try {\n                            $(JQueryEscape(objSetFocus)).focus().select();\n                        } catch (e) {\n                            // ignore errors\n                        }\n                    });\n                break;\n            case 2 : //FieldError\n                var id = 'error:' + ca.formDefId + ':' + ca.fieldDefId + ':' + ca.id;\n                var obj = $('#' + JQueryEscape(id));\n                if (obj.length == 0) {\n                    AlertMessage(ca.message+\" <br/>Could not find Error Tag for \" + ca.fieldHtml);\n                } else\n                    obj.html(ca.message);\n                break;\n\n            case 5 : //RefreshField\n                var id = 'fieldContainer:' + ca.formDefId + ':' + ca.fieldDefId + ':' + ca.id;\n                var obj = $('#' + JQueryEscape(id));\n                if (obj.length == 0) {\n                    alert(\"Internal Error: Could not find \" + id);\n                } else {\n                    if (ca.outer)\n                        obj[0].outerHTML = ca.fieldHtml;\n                    else\n                        obj.html(ca.fieldHtml);\n                    if (ca.JsStr)\n                        eval(ca.JsStr);\n                    SetFieldReadonly(pageData);\n                    if (ResetTableScrollHeaders())\n						$(window).resize();\n\n                }\n                break;\n            case 22 : //SetPageDirty\n                SetDirty(ca.Value == \"1\" ? true : false);\n                break;\n            case 23 : //OpenUrl\n                jQuery('<form action=\"' + ca.url + '\" method=\"post\" target=\"' + ca.id + '\">' + ca.message + '</form>')\n                    .appendTo('body').submit().remove();\n\n                break;\n            case 16 : //DownloadFile\n                jQuery('<form action=\"' + ca.url + '\" method=\"post\"><input type=\"hidden\" name=\"' + ca.message + '\" value=\"' + ca.Value + '\"></form>')\n                    .appendTo('body').submit().remove();\n\n                break;\n			case 24 : //RemoteRefresh\n                AjaxFunctionCall(\"RefreshField\",ca.instanceId,ca.id , ca.fieldDefId, false, obj);\n                break;\n            default:\n                alert(\"Internal Error: Could not find AppPressResponseType:\" + ca.appPressResponseType);\n                break;\n        }\n    }\n}\n\nfunction ExecuteAppPressResponse(a,instanceId) {\n    if (a.appPressResponse != null) {\n        var appPressResponse = a.appPressResponse;\n        a.appPressResponse = null;\n        _ExecuteAppPressResponse(a,instanceId, appPressResponse, 0);\n        a.appPressResponse = null;\n    }\n}\n\nfunction UnSelectRestSelectRow(obj) {\n    var s = obj.id.split(\":\");\n    if (s.length < 5) {\n        alert(\"Invalid Object Id:\" + obj.id);\n    }\n    var formFieldType = s[1];\n    var formName = s[2];\n    var fieldName = s[3];\n    var formId = s[4];\n    $(JQueryEscape(\"input[id^='AppPress:\" + formFieldType + \":\" + formName + \":\" + fieldName + \":']\")).each(function() { //loop through each checkbox\n        if (this.id != obj.id)\n            this.checked = false; //select all checkboxes with class \"checkbox1\"               \n    });\n\n}\n\nfunction OnChange(obj, instanceId, always) {\n\n    a.RefreshFields = new Array();\n    $.each(a.DependentFields,\n        function(index, value) {\n            $.each(value, function(index1, value1) {\n                if (value1 == obj.name || value1 == obj.id) // for Radios Name contains field id\n                    a.RefreshFields.push(index)\n            })\n        })\n\n    if (always || a.RefreshFields.length > 0) {\n        var s = obj.id.split(\":\");\n        if (s.length < 5) {\n            alert(\"Invalid Object Id:\" + obj.id);\n        }\n        var formFieldType = s[1];\n        var formName = s[2];\n        var fieldName = s[3];\n        var formId = s[4];\n        AjaxFunctionCall(\"OnChange\", instanceId, formId, fieldName, false, obj);\n    }\n\n}\n\nfunction DeleteFile(objId, instanceId) {\n    var obj = document.getElementById(objId);\n    a.RefreshFields = new Array();\n    $.each(a.DependentFields,\n        function(index, value) {\n            $.each(value, function(index1, value1) {\n                if (value1 == obj.name || value1 == obj.id) // for Radios Name contains field id\n                    a.RefreshFields.push(index)\n            })\n        })\n\n\n    var s = obj.id.split(\":\");\n    if (s.length < 5) {\n        alert(\"Invalid Object Id:\" + obj.id);\n    }\n    var formFieldType = s[1];\n    var formName = s[2];\n    var fieldName = s[3];\n    var formId = s[4];\n    AjaxFunctionCall(\"DeleteFile\", instanceId, formId, fieldName, false, obj);\n}\n\nfunction GetFormData(a, clickEvent, checkAutoComplete) {\n    // Scan all fields and Create a new FormData list\n    var evn = null;\n    if (clickEvent)\n        evn = clickEvent;\n    else if (this.event && this.event.type == \"click\")\n        evn = this.event;\n    $.each(a.formDatas, function(index, formData) {\n        if (formData != null)\n            $.each(formData.fieldValues, function(index, fieldValue) {\n                var formField = FindFormField(fieldValue);\n                if (formField != null)\n                    switch (formField.Type) {\n                        case 7 :\n                            if (!formField.Static)\n                                fieldValue.Value = null;\n                            break;\n                    }\n            })\n    })\n    var objs = $(\"[id^='\" + JQueryEscape(\"AppPress:\") + \"']\").filter(':input');\n    for (var ii = 0; ii < objs.length; ++ii) {\n        var obj = $(objs[ii]);\n        var s = obj[0].id.split(\":\");\n        if (s.length < 5) {\n            alert(\"Invalid Object Id:\" + obj[0].id);\n        }\n        for (var jj = 0; jj < objs.length; ++jj)\n            if (jj != ii && objs[jj].id == obj[0].id)\n                alert(\"Found 2 objects with Id: \" + obj[0].id);\n        var formFieldType = parseInt(s[1]);\n        var formDefName = s[2];\n        var fieldName = s[3];\n        var formDataId = s[4];\n        switch (formFieldType) {\n            case 2 :\n            case 1 :\n            case 3 :\n            case 4 :\n            case 8 :\n                {\n                    var formData = FindFormData(formDefName, formDataId);\n                    var fieldValue = GetFieldValue(formData, fieldName);\n                    fieldValue.Value = obj.val() == '' ? null : obj.val();\n                    break;\n                }\n            case 5 :\n                {\n                    var formData = FindFormData(formDefName, formDataId);\n                    var fieldValue = GetFieldValue(formData, fieldName);\n                    fieldValue.Value = obj.prop(\"checked\") ? \"1\" : \"0\";\n                    break;\n                }\n            case 6 :\n                {\n                    var formData = FindFormData(formDefName, formDataId);\n                    var fieldValue = GetFieldValue(formData, fieldName);\n                    var style = FindFormField(fieldValue).Style;\n                    if (style == 5 ) {\n                        if (obj.prop(\"checked\"))\n                            fieldValue.Value = obj.val();\n                    } else if (style == 9 ) {\n                        if (checkAutoComplete && fieldValue.Value == null && obj.val() != \"\") {\n                            alert('Auto Complete field should have valid value');\n                            obj.focus();\n                            return false;\n                        }\n                    } else {\n                        fieldValue.Value = obj.val();\n                        if (fieldValue.Value == \"\")\n                            fieldValue.Value = null;\n                    }\n                    break;\n                }\n            case 7 :\n                {\n                    var formData = FindFormData(formDefName, formDataId);\n                    var fieldValue = GetFieldValue(formData, fieldName);\n                    var style = FindFormField(fieldValue).Style;\n                    if (obj.prop(\"checked\"))\n                        if (fieldValue.Value == null)\n                            fieldValue.Value = obj.val();\n                        else\n                            fieldValue.Value += \",\" + obj.val()\n\n\n                    break;\n                }\n            case 11 :\n                {\n                    var formData = FindFormData(formDefName, formDataId);\n                    var fieldValue = GetFieldValue(formData, fieldName);\n                    fieldValue.Value = obj.attr(\"FileId\");\n                    if (typeof(fieldValue.Value) == \"undefined\" || fieldValue.Value == '')\n                        fieldValue.Value = null;\n                    break;\n                }\n        }\n    }\n    return true;\n}\n\nvar clickEvent = null;\n\nfunction CatchEvent(event) {\n    clickEvent = event;\n}\nvar disablePageCount = 0;\n\nfunction DisablePage() {\n    if (disablePageCount == 0) {\n        if ($(\"#overlay\").length == 0)\n            $(\"body\").append('<div id=\"overlay\" style=\"opacity: 0.5;background-color:grey;position:fixed;top:0;left:0;bottom:0px;right:0px;z-index:99999\"></div>');\n        else\n            $(\"#overlay\").show();\n    }\n    disablePageCount++;\n}\n\nfunction RemoveDisablePage() {\n    disablePageCount--;\n    if (disablePageCount == 0) {\n        if ($(\"#overlay\").length > 0)\n            $(\"#overlay\").hide();\n    }\n}\n\nfunction HandleShortcut(obj) {\n    if ($promptDialog == null && $alertDialog == null) {\n        obj.click();\n    }\n}\n\nfunction HandleFocusShortcut(obj) {\n    if ($promptDialog == null && $alertDialog == null && obj.is(\":focus\")) {\n        obj.change();\n    }\n}\n\nvar isAjaxCallRunning = false;\n\nfunction AjaxFunctionCall(functionName, instanceId, formId, fieldName, NoSubmit, sender, result) {\n    if (sender && sender.attributes && sender.attributes['disabled'] && sender.attributes['disabled'].value == 'disabled') // could not do this with jQuery\n        return false; // for disabling links\n    //event.preventDefault();\n    if (isAjaxCallRunning) {\n        var interval = setInterval(\n            function() {\n                if (!isAjaxCallRunning) {\n                    clearInterval(interval);\n                    AjaxFunctionCall(functionName, instanceId, formId, fieldName, NoSubmit, sender, result);\n                }\n            },\n            250);\n    } else {\n        isAjaxCallRunning = true;\n        a.screenWidth = screen.width;\n        a.screenHeight = screen.height;\n        a.documentWidth = $(document).width();\n        a.documentHeight = $(document).height();\n        a.windowWidth = $(window).width();\n        a.windowHeight = $(window).height();\n        if (NoSubmit)\n            a.FormDatas = null;\n        else\n        // get clientChanges\n        if (!GetFormData(a, clickEvent, true)) {\n            isAjaxCallRunning = false;\n            return;\n        }\n        a.appPressResponse = null;\n        a.rootFormData = new Object();\n        a.rootFormData.formDefId = rootFormName;\n        a.rootFormData.id = rootFormId;\n        a.fieldValue = new Object();\n        a.fieldValue.fieldDefId = fieldName;\n        a.formDataId = formId;\n        a.PromptClientResult = result;\n        a.pageTimeStamp = pageTimeStamp;\n        a.PageDirty = GetDirty();\n		a.autoCompleteTerm = null;\n        var pageurl = unescape(GetBaseUrl(instanceId));\n        sender = $(sender);\n        var disablePageTimer = null;\n        if (functionName == 'OnChange') {\n            disablePageTimer = setTimeout(function() {\n                disablePageTimer = null;\n                DisablePage();\n            }, 2500)\n        } else\n            DisablePage();\n\n        var formFields = a.formFields;\n        a.formFields = null; // do not post it back\n\n		a.instanceId = parseInt(instanceId);\n        \n		var s = stringifyP(a);\n		\n        a.formFields = formFields;\n		if (functionName != null)\n	        pageurl += \"?functionCall=\" + functionName;\n        $.ajax({\n            type: 'POST',\n            url: pageurl,\n            data: {\n                'p': s\n            },\n            success: function(result) {\n                if (result != null && result != \"\") // comes in case Serialize throws a error\n                {\n                    var p1;\n                    try {\n                        p1 = eval('(' + result + ')');\n                    } catch (ex) {\n                        RemoveDisablePage();\n                        isAjaxCallRunning = false;\n                        AlertMessage(result, 700);\n                        return;\n                    }\n                    if (p1.formDatas == null)\n                    // error case, show the error without disturbing p\n                        ExecuteAppPressResponse(p1,instanceId);\n                    else {\n                        a = p1;\n                        ExecuteAppPressResponse(a,instanceId);\n                    }\n                }\n                if (functionName == 'OnChange')\n                    if (disablePageTimer != null)\n                        clearTimeout(disablePageTimer);\n                    else\n                        RemoveDisablePage();\n                else\n                    RemoveDisablePage();\n                isAjaxCallRunning = false;\n            },\n            error: function(obj, errorStr, errorThrown) {\n                AlertMessage('Server Not Responding. Please retry.');\n                if (functionName == 'OnChange')\n                    if (disablePageTimer != null)\n                        clearTimeout(disablePageTimer);\n                    else\n                        RemoveDisablePage();\n                else\n                    RemoveDisablePage();\n                isAjaxCallRunning = false;\n            },\n            complete: function(obj, status) {\n                //if (!PageBeingRefreshed)\n                //	RemoveDisablePage();\n                isAjaxCallRunning = false;\n            }\n        });\n    }\n}\n\nfunction AutoCompleteCall(instanceId, formId, fieldName, term, add) {\n\n    a.screenWidth = screen.width;\n    a.screenHeight = screen.height;\n    a.documentWidth = $(document).width();\n    a.documentHeight = $(document).height();\n    a.windowWidth = $(window).width();\n    a.windowHeight = $(window).height();\n    // get clientChanges\n    GetFormData(a, clickEvent, false);\n    a.appPressResponse = null;\n    a.rootFormData = new Object();\n    a.rootFormData.formDefId = rootFormName;\n    a.rootFormData.id = rootFormId;\n    a.fieldValue = new Object();\n    a.fieldValue.fieldDefId = fieldName;\n    a.formDataId = formId;\n\n    a.autoCompleteTerm = term;\n    var s = stringifyP(a);\n    var pageurl = unescape(GetBaseUrl(instanceId));\n    pageurl += \"?functionCall=AutoCompleteOptions\";\n    $.ajax({\n        type: 'POST',\n        url: pageurl,\n        data: {\n            'p': s\n        },\n        success: function(result) {\n            var responseData = eval('(' + result + ')');\n            ExecuteAppPressResponse(responseData,instanceId);\n            add(responseData.autoCompleteOptions);\n        },\n        error: function(obj, errorStr, errorThrown) {\n            AlertMessage('Server Not Responding. Please retry.');\n        }\n\n    });\n}\n\nfunction GetTimeStamp() {\n    var date = new Date();\n    return date.getDay() + \"\" + date.getMonth() + \"\" + date.getYear() + \"\" + date.getHours() + \"\" + date.getMinutes() + \"\" + date.getSeconds();\n}\n\n\nfunction OpenFileWindow(sender) {\n    this.open($(sender).attr('src') + '&Download=true', '');\n\n}\n\nfunction SetElementHtml(elementId, markup) {\n    var decodedMarkup = unescape(markup);\n    $('#' + elementId).append(decodedMarkup);\n\n}\n\nfunction CheckUncheckAll(obj, id) {\n	var idParts = id.split(\":\");\n	var idPrefix = idParts[0]+\":\"+idParts[1]+\":\"+idParts[2]+\":\"+idParts[3]+\":\";\n    $(\"[type='checkbox'][id^='\" + JQueryEscape(idPrefix) + \"']\").prop(\"checked\", $(obj).prop(\"checked\"));\n}\n\nfunction GetDirty() {\n    return popupDialogs.length == 0 ? __IsPageDirty : popupDialogs[popupDialogs.length - 1].IsPageDirty;\n}\n\nfunction GetWarnOnDirtyClose() {\n    return popupDialogs.length == 0 ? WarnOnDirtyClose : popupDialogs[popupDialogs.length - 1].WarnOnDirtyClose;\n}\n\nfunction SetWarnOnDirtyClose() {\n    if (popupDialogs.length == 0)\n        WarnOnDirtyClose = true;\n    else\n        popupDialogs[popupDialogs.length - 1].WarnOnDirtyClose = true;\n}\n\n\nfunction SetFieldReadonly(a) {\n    $.each(a.formDatas, function(index, formData) {\n        $.each(formData.fieldValues, function(index, fieldValue) {\n                var formField = FindFormField(fieldValue)\n                if (formField != null)\n                    switch (formField.Type) {\n                        case 6 :\n                        case 4 :\n                        case 1 :\n                        case 2 :\n                        case 8 :\n                        case 11 :\n                        case 12 :\n                        case 5 :\n                            {\n                                var dirty = null;\n                                switch (fieldValue.ReadOnly) {\n                                    case 1 :\n                                        dirty = \"disabled\";\n                                        break;\n                                }\n                                if (FindFormField(fieldValue).Style == 5 ) {} else {\n                                    var id = \"AppPress:\" + FindFormField(fieldValue).Type + \":\" + formData.formDefId + ':' + fieldValue.fieldDefId + ':' + formData.id;\n                                    if (dirty != null)\n                                        $('#' + JQueryEscape(id)).attr('disabled', dirty);\n                                    else\n                                        $('#' + JQueryEscape(id)).removeAttr('disabled');\n                                }\n\n                            }\n                            break;\n                    }\n            }\n\n        )\n    })\n}\n\nfunction SetDirty(dirty) {\n    if (typeof(dirty) == \"undefined\")\n        dirty = true;\n    var pageDirty = GetDirty();\n    if (pageDirty != dirty) {\n        if (popupDialogs.length == 0) {\n            __IsPageDirty = dirty;\n            SetFieldReadonly(a);\n        } else {\n            popupDialogs[popupDialogs.length - 1].IsPageDirty = dirty;\n            SetFieldReadonly(popupDialogs[popupDialogs.length - 1].p);\n        }\n    }\n}\n\nfunction AppPressAutoComplete(id, onChange, instanceId) {\n    var s = id.split(\":\");\n    if (s.length < 5) {\n        alert(\"Invalid Object Id:\" + obj.id);\n    }\n    var formFieldType = s[1];\n    var formDefId = s[2];\n    var fieldDefId = s[3];\n    var formId = s[4];\n    $('#' + JQueryEscape(id)).autocomplete({\n            source: function(req, add) {\n                AutoCompleteCall(instanceId, formId, fieldDefId, req.term, add)\n            },\n            select: function(event, ui) {\n                eval('var formData = FindFormData(formDefId,formId);var fieldValue = GetFieldValue(formData, fieldDefId);fieldValue.Value = ui.item.id;' +\n                    onChange);\n            },\n            open: function() {\n                $('#' + JQueryEscape(id)).bind('blur', function() {\n                    if (typeof $(this).data('uiItem') == 'undefined') {\n                        $(this).val(null);\n                    }\n                });\n            },\n            close: function() {\n                $('#' + JQueryEscape(id)).unbind('blur');\n            }\n        })\n        .focusout(function() {\n            if (!$(this).val()) {\n                eval('var formData = FindFormData(formDefId,formId);var fieldValue = GetFieldValue(formData, fieldDefId);fieldValue.Value = null;' +\n                    onChange);\n            }\n        })\n        .bind('paste', function(e) {\n            setTimeout(function() {\n                $('#' + JQueryEscape(id)).autocomplete('search', $('#' + JQueryEscape(id)).val());\n            }, 0);\n        });\n}"+
"/**\n* http://www.openjs.com/scripts/events/keyboard_shortcuts/\n* Version : 2.01.B\n* By Binny V A\n* License : BSD\n*/\nshortcut = {\n    'all_shortcuts': {}, //All the shortcuts are stored in this array\n    'add': function (shortcut_combination, callback, opt) {\n        //Provide a set of default options\n        var default_options = {\n            'type': 'keydown',\n            'propagate': false,\n            'disable_in_input': false,\n            'target': document,\n            'keycode': false\n        }\n        if (!opt) opt = default_options;\n        else {\n            for (var dfo in default_options) {\n                if (typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];\n            }\n        }\n\n        var ele = opt.target;\n        if (typeof opt.target == 'string') ele = document.getElementById(opt.target);\n        var ths = this;\n        shortcut_combination = shortcut_combination.toLowerCase();\n\n        //The function to be called at keypress\n        var func = function (e) {\n            e = e || window.event;\n\n            if (opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields\n                var element;\n                if (e.target) element = e.target;\n                else if (e.srcElement) element = e.srcElement;\n                if (element.nodeType == 3) element = element.parentNode;\n\n                if (element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;\n            }\n\n            //Find Which key is pressed\n            if (e.keyCode) code = e.keyCode;\n            else if (e.which) code = e.which;\n            var character = String.fromCharCode(code).toLowerCase();\n\n            if (code == 188) character = \",\"; //If the user presses , when the type is onkeydown\n            if (code == 190) character = \".\"; //If the user presses , when the type is onkeydown\n\n            var keys = shortcut_combination.split(\"+\");\n            //Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked\n            var kp = 0;\n\n            //Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken\n            var shift_nums = {\n                \"`\": \"~\",\n                \"1\": \"!\",\n                \"2\": \"@\",\n                \"3\": \"#\",\n                \"4\": \"$\",\n                \"5\": \"%\",\n                \"6\": \"^\",\n                \"7\": \"&\",\n                \"8\": \"*\",\n                \"9\": \"(\",\n                \"0\": \")\",\n                \"-\": \"_\",\n                \"=\": \"+\",\n                \";\": \":\",\n                \"'\": \"\\\"\",\n                \",\": \"<\",\n                \".\": \">\",\n                \"/\": \"?\",\n                \"\\\\\": \"|\"\n            }\n            //Special Keys - and their codes\n            var special_keys = {\n                'esc': 27,\n                'escape': 27,\n                'tab': 9,\n                'space': 32,\n                'return': 13,\n                'enter': 13,\n                'backspace': 8,\n\n                'scrolllock': 145,\n                'scroll_lock': 145,\n                'scroll': 145,\n                'capslock': 20,\n                'caps_lock': 20,\n                'caps': 20,\n                'numlock': 144,\n                'num_lock': 144,\n                'num': 144,\n\n                'pause': 19,\n                'break': 19,\n\n                'insert': 45,\n                'home': 36,\n                'delete': 46,\n                'end': 35,\n\n                'pageup': 33,\n                'page_up': 33,\n                'pu': 33,\n\n                'pagedown': 34,\n                'page_down': 34,\n                'pd': 34,\n\n                'left': 37,\n                'up': 38,\n                'right': 39,\n                'down': 40,\n\n                'f1': 112,\n                'f2': 113,\n                'f3': 114,\n                'f4': 115,\n                'f5': 116,\n                'f6': 117,\n                'f7': 118,\n                'f8': 119,\n                'f9': 120,\n                'f10': 121,\n                'f11': 122,\n                'f12': 123\n            }\n\n            var modifiers = {\n                shift: { wanted: false, pressed: false },\n                ctrl: { wanted: false, pressed: false },\n                alt: { wanted: false, pressed: false },\n                meta: { wanted: false, pressed: false}	//Meta is Mac specific\n            };\n\n            if (e.ctrlKey) modifiers.ctrl.pressed = true;\n            if (e.shiftKey) modifiers.shift.pressed = true;\n            if (e.altKey) modifiers.alt.pressed = true;\n            if (e.metaKey) modifiers.meta.pressed = true;\n\n            for (var i = 0; k = keys[i], i < keys.length; i++) {\n                //Modifiers\n                if (k == 'ctrl' || k == 'control') {\n                    kp++;\n                    modifiers.ctrl.wanted = true;\n\n                } else if (k == 'shift') {\n                    kp++;\n                    modifiers.shift.wanted = true;\n\n                } else if (k == 'alt') {\n                    kp++;\n                    modifiers.alt.wanted = true;\n                } else if (k == 'meta') {\n                    kp++;\n                    modifiers.meta.wanted = true;\n                } else if (k.length > 1) { //If it is a special key\n                    if (special_keys[k] == code) kp++;\n\n                } else if (opt['keycode']) {\n                    if (opt['keycode'] == code) kp++;\n\n                } else { //The special keys did not match\n                    if (character == k) kp++;\n                    else {\n                        if (shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase\n                            character = shift_nums[character];\n                            if (character == k) kp++;\n                        }\n                    }\n                }\n            }\n\n            if (kp == keys.length &&\n						modifiers.ctrl.pressed == modifiers.ctrl.wanted &&\n						modifiers.shift.pressed == modifiers.shift.wanted &&\n						modifiers.alt.pressed == modifiers.alt.wanted &&\n						modifiers.meta.pressed == modifiers.meta.wanted) {\n                callback(e);\n\n                if (!opt['propagate']) { //Stop the event\n                    //e.cancelBubble is supported by IE - this will kill the bubbling process.\n                    e.cancelBubble = true;\n                    e.returnValue = false;\n\n                    //e.stopPropagation works in Firefox.\n                    if (e.stopPropagation) {\n                        e.stopPropagation();\n                        e.preventDefault();\n                    }\n                    return false;\n                }\n            }\n        }\n        this.all_shortcuts[shortcut_combination] = {\n            'callback': func,\n            'target': ele,\n            'event': opt['type']\n        };\n        //Attach the function with the event\n        if (ele.addEventListener) ele.addEventListener(opt['type'], func, false);\n        else if (ele.attachEvent) ele.attachEvent('on' + opt['type'], func);\n        else ele['on' + opt['type']] = func;\n    },\n\n    //Remove the shortcut - just specify the shortcut and I will remove the binding\n    'remove': function (shortcut_combination) {\n        shortcut_combination = shortcut_combination.toLowerCase();\n        var binding = this.all_shortcuts[shortcut_combination];\n        delete (this.all_shortcuts[shortcut_combination])\n        if (!binding) return;\n        var type = binding['event'];\n        var ele = binding['target'];\n        var callback = binding['callback'];\n\n        if (ele.detachEvent) ele.detachEvent('on' + type, callback);\n        else if (ele.removeEventListener) ele.removeEventListener(type, callback, false);\n        else ele['on' + type] = false;\n    }\n}"+
"";
                    internal static string AppPressCSS = "/*Help Url: http://michaelb.org/projects/jquery-silk-icons/*/\n\n.appPressReport {\n    margin: 15px auto auto;\n    width: 99%;\n}\n\n.appPressReport table {\n    width: 100%;\n    color: #444;\n    font-size: 11px;\n    margin-top: 0px;\n    font-family: segoe ui;\n    border-collapse: collapse;\n    border: 1px black solid;\n}\n\n    .appPressReport table tr th {\n        padding: 3px 5px !important;\n        background-color: #747474 !important;\n        border: 1px solid #ddd !important;\n        color: White !important;\n        font-size: 12px;\n    }\n\n    .appPressReport table tr:nth-child(odd) {\n        /* background: #f9f9f9;*/\n    }\n\n    .appPressReport table tr td {\n        padding-left: 3px;\n        padding-right: 2px;\n        border: 1px solid #ddd !important;\n    }\n\n"+
"";
                    internal static string PageDesignerHtml = "";
                    }

/*
// Paste Following into AppPressClasses.cs if not able to build AppPress.dll because of error in generating this file


using System;
using System.Collections.Generic;
using AppPressFramework;

namespace AppPress
{


	internal class FileTexts
                    {
                    internal static string AppPressJS = "";
					internal static string AppPressCSS = "";
					internal static string PageDesignerHtml = "";
                    }
    public static class FormDefs
    {
        public static string CodeFragmentExecute(PageData a, int key)
        {
            return null;
        }
		public static FormDef PageDesignerFormDef;
        public static FormDef SessionExpiredFormDef;
        public static FormDef FieldFormDef;

        public static FormDef[] formDefs = { };
    }


}
*/
}